package com.example.himalayaproject.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.himalayaproject.R;
import com.example.himalayaproject.adapter.SettingRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

public class SettingActivity extends AppCompatActivity implements SettingRecyclerAdapter.OnChildClickListener, View.OnClickListener {
  private RecyclerView recyclerView;
    private String[] titles = new String[]{"特色闹钟","定时关闭","2G/3G/4G播放和下载","下载和缓存设置","下载位置","推送设置","检查更新","喜马拉雅帮助","关于"};
    private ImageView back_iv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        aboutRecycler();
    }

    private void aboutRecycler() {
        recyclerView = (RecyclerView) findViewById(R.id.activity_setting_recycler);
        back_iv = (ImageView) findViewById(R.id.owner_login_back_iv);
        List<String> list = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            list.add(titles[i]);
        }
        SettingRecyclerAdapter adapter = new SettingRecyclerAdapter(this,list);
        recyclerView.setAdapter(adapter);
        adapter.setListener(this);
        back_iv.setOnClickListener(this);
    }
    //跳转界面
    @Override
    public void onChildClick(int position) {
        switch (position) {
            default:
                Toast.makeText(this, "点击了第"+position+"条目", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case  R.id.owner_login_back_iv:
                finish();
                overridePendingTransition(R.anim.anim_enter,R.anim.back_enter);
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            finish();
            overridePendingTransition(R.anim.anim_enter,R.anim.back_enter);
            return false;
        }else {
            return super.onKeyDown(keyCode, event);
        }
    }
}
